<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Editassociationuser action form.
 * 编辑社团用户的表格.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.2
 * 
 * 0.2)  Adds the editor feature.
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_util.php';
require_once INSTALLDIR . '/lib/slh_form.php';
require_once INSTALLDIR . '/lib/slh_editor.php';

require_once INSTALLDIR . '/classes/Avatar.php';

class EditassociationuserForm extends Form
{
	/**
	 * The editor widget.
	 */
	var $editor;
	
	/**
	 * Avatars url.
	 */
	var $normalurl;
	var $tinyurl;
	
	function prepareData()
	{
		$this->editor = new Editor('rendered', $this->out);
		
		$normalAvatar = $this->getField('normalAvatar');
		$tinyAvatar = $this->getField('tinyAvatar');
		
		if ($normalAvatar != false && $tinyAvatar != false) {
			$this->normalurl = $normalAvatar->avatarurl();
			$this->tinyurl = $tinyAvatar->avatarurl();
		} else {
			$this->normalurl = Avatar::defaultImage(AVATAR_NORMAL_SIZE);
			$this->tinyurl = Avatar::defaultImage(AVATAR_TINY_SIZE);
		}
		
		$this->out->hidden('user_id', $this->getField('guser_id'));
	}
	
	/**
	 * ID of the from
	 */
	function id()
	{
		return 'id_form_editassociationuser';
	}
	
	/**
	 * Class of the form.
	 */
	/*
	function formClass()
	{
		// return 'class_settingsform';
	}
	*/
	
	/**
	 * Action of the form
	 * 
	 * Return the string URL of the action.
	 */
	function action()
	{
		return slh_action2url('editassociationuser', array('guser_id' => $this->getField('guser_id')));
	}
	
	/**
	 * Name of the form
	 */
	function formLegend()
	{
		$this->out->element('legend', null, 'edit association');
	}
	
	/**
	 * Token of the form.
	 */
	function formToken()
	{
		$this->out->hidden('formtoken', 'editassociation');
	}
	
	/**
	 * Data elements.
	 */
	function formData()
	{
		$this->out->elementStart('dl', array('class' => 'cls_dl_form'));
		$this->out->element('dt', '编辑社团用户');
		
		$this->out->element('dt', null, '账户信息');
		$this->out->elementStart('dd');
		$this->out->elementStart('ul');
			$this->out->elementStart('li');
			$this->out->readonly('username',
								 '用户名',
								 $this->getField('username'),
								 '[只读]登陆用的用户名呃.');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->element('a', array('href' => slh_action2url('deletepassword',
								  	   							  	array('guser_id' => $this->getField('guser_id'))),
										   'title'=> '删除原来的密码.'),
								'重置密码');
			$this->out->inputtips('重置这个密码就是说把它设置为用户名吼.');
			$this->out->elementEnd('li');
		$this->out->elementEnd('ul');
		$this->out->elementEnd('dd');
		
		$this->out->element('dt', null, '账户信息');
		$this->out->elementStart('dd');
		$this->out->elementStart('ul');
			$this->out->elementStart('li');
			$this->out->readonly('cnname',
							  	 '中文名称',
							  	 $this->getField('cnname'),
							  	 '[只读]社团的完整中文名称.');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->input('enname',
							  '英文名称', 
							  $this->getField('enname'),
							  '[选填]英文英文吼吼.');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->input('pinyin',
							  '中文拼音', 
							  $this->getField('pinyin'),
							  '[选填]用于简化搜索.');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->input('weibo_id',
							  '新浪微博id', 
							  $this->getField('weibo_id'),
							  '[选填]可以用来更新显示社团微博的最新内容.');
			$this->out->elementEnd('li');

			/*
			$this->out->elementStart('li');
			$this->out->textarea('rendered',
								 '社团的简介',
								 6,
								 72,
								 $this->getField('rendered'),
								 '[选填]社团的基本情况和相关说明啦.');
			$this->out->elementEnd('li');
			*/
			$this->out->element('dt', null, '社团的简介');
			$this->out->inputtips('[选填]社团的基本情况和相关说明啦.');
			$this->out->elementStart('li', 'cls_li_eaditor');
			$this->editor->show();
			$this->out->elementEnd('li');
		$this->out->elementEnd('ul');
		$this->out->elementEnd('dd');
		
		$this->out->element('dt', null, '头像信息');
		$this->out->elementStart('dd');
		$this->out->elementStart('ul', array('class' => 'ul_cls_avatarpreview'));
			$this->out->elementStart('li');
			$this->out->element('h5', null, '正常:');
			$this->out->elementStart('div', array('class' => 'div_cls_normalavatar'));
			$this->out->element('img', array('src'	 => $this->normalurl));
			$this->out->elementEnd('div');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->element('h5', null, '微型:');
			$this->out->elementStart('div', array('class' => 'div_cls_tinyavatar'));
			$this->out->element('img', array('src'	 => $this->tinyurl));
			$this->out->elementEnd('div');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->element('a', array('class' => 'cls_a_asbutton',
										   'href' => slh_action2url('editavatar',
								  	   							  	array('guser_id' => $this->getField('guser_id'))),
										   'title'=> '设定这个社团的头像!'),
								'编辑头像...');
			$this->out->elementEnd('li');
		$this->out->elementEnd('ul');
		$this->out->elementEnd('dd');
		
		$this->out->elementEnd('dl');
	}
	
	/**
	 * Action elements.
	 */
	function formActions()
	{
		$this->out->elementStart('div', 'formaction');
		$this->out->submit('submit',
						   '修改',
						   'submit',
						   null,
						   '修改当前的用户信息.');
		$this->out->elementEnd('div');
	}
}